{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 信息熵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def entropy(p):\n",
    "    \"\"\"\n",
    "    二分类问题的信息熵\n",
    "    :param p: 其中一个分类的概率\n",
    "    :return: \n",
    "    \"\"\"\n",
    "    return -p * np.log(p) - (1-p)*np.log(1-p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.linspace(0.01,0.99,200)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3Xd0lNe19/HvVkdCokmAEAIJEEV0EJgSbNzBBdwBV+IW23FLt6/TrnPj3Ng3dm58SWzcnbjGFdvY4IILHdERVaJKFBVQF6r7/WMGvQoRaACNnin7s9asNeWM5vdQZuuc8zzniKpijDHGAIQ4HcAYY4zvsKJgjDGmkRUFY4wxjawoGGOMaWRFwRhjTCMrCsYYYxpZUTDGGNPIioIxxphGVhSMMcY0CnM6wKmKj4/XlJQUp2MYY4xfWb16daGqJrTUzu+KQkpKCpmZmU7HMMYYvyIiezxpZ8NHxhhjGllRMMYY08irRUFEpojINhHJFpGHmnn9KRFZ575tF5Fib+Yxxhhzcl6bUxCRUGAOcCGQC6wSkXmquvlYG1X9UZP29wEjvZXHGGN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wKKyCXu9652r5P/sfv5GPfa+ivdewY0tyqsMWfMioIJCu71rqYCG93LIMwAJqrqCFxX/t7gbhqDa0364cBK4C3gAffjC4AqXOvslKjqGGAMcIeIpLrfPxJXryAd1/r/E1X1L7iWcj5XVc91t3tEVTOAYcA5IjJMRKJwLUkyVVVHAwlNDuERXEuzjMW1R8YTIhLTmn9GxkCALHNhzEm0E5F17vvf4Vru5E5gNLDKvfRHO+DYulD1wLvu+wOAA6q6CkBVSwFE5CJgmIhc427XAdeiczXASlXNdbdbB6QAi5vJdZ2I3Inr/2AiriISAux0L2QH8IY7K8BFwDQR+an7cRTQC9hyin8expyUFQUT6KrcvYFG7s2VXlHVh5tpf1RV61v4mQLcp6oLjvu5k4Gmq9DW08z/MXev4qfAGFU9IiIv4/qSb+kzr1bVbS20M+aM2PCRCUZfAteISFcAEeksze9dvQ1IFJEx7nax7mGoBcDdIhLufr6/B0M5ZbiW9AbXDmEVQImIdMM1rHXs8/rI/98/fEaT9y8A7nMXtGOr3xrT6qynYIKOqm4WkV8CC8W1IU8t8ENgz3HtakRkBvC0iLTDNZ9wAfA8rmGhNe4v6QLgihY+di7wmYjsV9VzRWQtsBXXrllL3J9XJSL3uNtV4Foy+pjfAX8GNrgz7wIuO+0/BGNOwFZJNcaHiEh7VS13F5s5wA5VfcrpXCZ42PCRMb7lDvcEdRauCexnHc5jgoz1FIwxxjSynoIxxphGVhSMMcY0sqJgjDGmkRUFY4wxjawoGGOMaWRFwRhjTKP/B7KuI5PFbP5EAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x106392208>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(x, entropy(x))\n",
    "plt.xlabel('Percentage')\n",
    "plt.ylabel('Entropy')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到概率越接近一半时，信息熵越大  \n",
    "数据越偏向其中一方（越偏斜），信息熵越小，不确定度越小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
